const path=require('path');
const htmlwebpackPlugin=require('html-webpack-plugin');
const cleanwebpackPlugin=require('clean-webpack-plugin');
const webpack = require('webpack');
//const ExtractTextPlugin=require('extract-text-webpack-plugin')


module.exports={
    entry:[
        'react-hot-loader/patch',   
        './src/index.js',
        
            ],
    devtool:'source-map',
    devServer:{
        contentBase:'./dist',
        hot:true
    },
    plugins:[
        new cleanwebpackPlugin(['dist']),
        new htmlwebpackPlugin({
            template: path.resolve(__dirname, './src/index.html'),
        }),
       // new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    mode: 'development', // 设置mode
    output:{
        filename:'bundle.js',
        path:path.resolve(__dirname,'dist')
    },
    module:{
        rules:[
            // 解析.css文件
            {
                test:/\.css$/,
                loaders:[
                    'style-loader',
                    'css-loader'
                ]
            },
            // 解析.scss文件
            {
                test:/\.scss$/,
                loaders:['style-loader','css-loader','sass-loader']
            },
            {
                test:/\.(png|svg|jpg|gif)$/,
                use:[
                    'file-loader'
                ]
            },
            {    
                test: /\.js$/,    
                exclude: /node_modules/,    
                loader: 'babel-loader'    ,
                query: {  
                    presets: ['react', 'es2015']  
                  }  
            }
        ]
    },
    resolve: {
        modules: [
             //设置绝对路径
            path.resolve('./src'),
            path.resolve('./node_modules')
        ]
    }
}